import {defineStore} from 'pinia'
import {computed, ref} from "vue";
//【命名】defineStore(id) ，此处id 应和文件名相同

//【导入】
//import storeLayout from "@/store/layoutStore.ts";

//【使用】
//storeDemo().demoStatus  ; storeDemo().demoStatus=20 ; storeDemo().demoFunction()
//注意括号
//storeDemo(). ✔️
//storeDemo.   ❌

//
// Demo
export default defineStore('storeDemo',
    () => {
        // 普通属性
        const demoStatus = ref(0)
        const closeMenu = ref(false)

        // 计算属性
        const demoComputed = computed(() => demoStatus.value * 2)

        // 方法
        function demoFunction() {
            demoStatus.value++
        }

        // 方法
        function setState(key: string, val: any) {
            (this as any)[key] = val;
        }

        return {
            closeMenu,
            demoStatus,
            demoFunction,
            demoComputed,
        }

    })
